#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:

    int rev(int n) {
        int res = 0;
        while (n) {
            res = res * 10 + n % 10;
            n /= 10;
        }
        return res;
    }
    int countNicePairs(vector<int>& nums) {
        unordered_map<int, int> hash;
        int ans = 0;
        //nums[i] - rev(nums[i]) == nums[j] - rev(nums[j])
        for (auto e : nums) {
            int r = rev(e);
            ans = (ans + hash[e - r]) % 1000000007;
            hash[e - r]++;
        }
        return ans;
    }
};